const {mongoose} = require('./database.js')

const userSchema = new mongoose.Schema({      // 用户表
    name: String,           // 用户名
    password:String,
    lastLogin: {
        type:Date,
        default:()=>new Date()
    },            // 最后登录时间
    status:{
        type:Number,
        default:1
    },              // 状态0/1
    role_id:{   //用户角色外键
        type: mongoose.Schema.Types.ObjectId,
        ref: 'role'
    }
})
const usersModel = mongoose.model('user',userSchema,'user')//数据库里的user表

const roleSchema = new mongoose.Schema({
  name: String,
  permissions: [String], // 权限menuid数组
  description: String,
  status: Number   //0/1
  // 其它字段可按需补充
});

const rolesModel = mongoose.model('role',roleSchema)//数据库里的roles表

const menuSchema = new mongoose.Schema({      // 菜单表
    title: String,              // 菜单名称
    path: String,               // 前端路由
    icon: String,               // 图标
    parentId: {
        type:String,
        default:'/'
    },           // 父级ID
})
const menuModel = mongoose.model('menu',menuSchema)//数据库里的menus表

const userqchema = new mongoose.Schema({      // 前端平台用户
    username: String,
    password: String,
    img: String,
    desc: String,
    name: String
})
const userqModel = mongoose.model('userq', userqchema)

const Pushchema = new mongoose.Schema({      // 推送信息表
    typeA: String,
    typeB: String,
    typeC: String,
    time: String,
    code: Number,
    content: String,
})
const PushModel = mongoose.model('Push', Pushchema)

const Messagechema = new mongoose.Schema({      // 信息暂存表
    userId: String,
    desc: String,
    time: String
})
const MessageModel = mongoose.model('Message', Messagechema)

const gexxlschema = new mongoose.Schema({      // 个人系统信息历史表
    userId: String,
    desc: String,
    time: String
})
const gexxlsModel = mongoose.model('gexxls', gexxlschema)

module.exports = {
    usersModel,
    rolesModel,
    menuModel,
    userqModel,
    PushModel,
    MessageModel,
    gexxlsModel
}
